# !/usr/bin/env python3.8
# -*- coding: utf-8 -*-
# @Time : 2021/7/13 15:29
# @Author : minvan
# @Email : jiangming8937@icloud.com
# @File : LOLITA.py
# @Software: PyCharm


import inspect
import json
import logging
import os
import sys
import time
import datetime
from locust import TaskSet, task, events
from locust.contrib.fasthttp import FastHttpUser
from locust_plugins import jmeter_listener
parent_path = os.path.dirname(sys.path[0])
if parent_path not in sys.path:
    sys.path.append(parent_path)
else:
    pass
from Params.params import params as request_data




#定义日志文件格式
planName =os.path.basename(__file__)+time.strftime("%Y-%m-%d=>%H:%M:%S", time.localtime())+".csv"
reportName = os.path.basename(__file__).split('.py')[0]+datetime.datetime.now().strftime("%Y-%m-%d*%H:%M:%S")+".html"
#定义Locust的配置文件路径
masterConf=os.path.abspath('../Configure/master.conf')
'''
Jmeeter example:
    @events.init.add_listener
    def on_locust_init(environment, **_kwargs):
            jmeter_listener.JmeterListener(env=environment, testplan="WebsiteTasks",results_filename=planName)
--------|------------------------------------------------------------|---------|------|------|------|------|------|------|
Timescale example:
    from locust_plugins import run_single_user, listeners
    from locust import HttpUser, task, events


    class MyUser(HttpUser):
        @task
        def index(self):
            self.client.post("/authentication/1.0/getResults", {"username": "something"})
    
        host = "http://example.com"


    @events.init.add_listener
    def on_locust_init(environment, **_kwargs):
        listeners.Timescale(env=environment, testplan="timescale_listener_ex")
    
    
    if __name__ == "__main__":
        # enable easy debugging from VS Code
        run_single_user(MyUser, init_listener=on_locust_init)
--------|------------------------------------------------------------|---------|------|------|------|------|------|------|     
Applications example:
    from locust_plugins.appinsights_listener import ApplicationInsights
    from locust import HttpUser, task, events, between
    
    
    class MyHttpUser(HttpUser):
        @task
        def index(self):
            self.client.get("/Guilhermeslucas/locust-plugins")
    
        host = "https://github.com"
        wait_time = between(4, 10)
    
    
    @events.init.add_listener
    def on_locust_init(environment, **_kwargs):
        ApplicationInsights(env=environment, instrumentation_key="<YOUR-APP-INSIGHTS-INSTRUMENTATION-KEY>")
'''

@events.init.add_listener
def on_locust_init(environment, **_kwargs):
    '''

    make report like Jmeter
    :param environment:
    :param _kwargs:
    :return:
    '''
    jmeter_listener.JmeterListener(env=environment,testplan=inspect.stack()[1][3],results_filename=planName)



class WebsiteTasks(TaskSet):

    def on_start(self):
        self.h=request_data("headers.json")
        self.d = request_data("serviceDetail.json")
        self.pointUpload = request_data("pointUpload.json")
        self.feeCalc = request_data("feeCalc.json")
        self.currentOrderInfo = request_data("CurrentOrderInfo.json")
        self.plazaTeams = request_data("PlazaTeams.json")
        self.routingEvent = request_data("RoutingEvent.json")
        self.orderInfoList = request_data("OrderInfoList.json")
        self.orderInfoPayment = request_data("OrderInfoPayment.json")
        self.teamJoinFree = request_data("TeamJoinFree.json")
        self.messageTemplateList = request_data("MessageTemplateList.json")
        self.orderActionWait = request_data("OrderActionWait.json")
        self.userBalanceDaily = request_data("UserBalanceDaily.json")
        self.orderInfoSubmitStart = request_data("OrderInfoSubmitStart.json")
        self.orderTrackList= request_data("OrderTrackList.json")
        self.feeTempServiceList = request_data("FeeTempServiceList.json")
        self.userMsgClose = request_data("UserMsgClose.json")
        self.messageTemplateSubscribe = request_data("MessageTemplateSubscribe.json")
        self.plazaListen =request_data("PlazaListen.json")
        self.orderInfoDetail = request_data("OrderInfoDetail.json")
        self.orderActionFinish = request_data("OrderActionFinish.json")
        self.userBadgeSettingSetup = request_data("UserBadgeSettingSetup.json")
        self.userBadgeListenSwitch = request_data("UserBadgeListenSwitch.json")
        self.orderFeeCurrentIntro = request_data("OrderFeeCurrentIntro.json")
        self.orderFeeConfirmInit = request_data("OrderFeeConfirmInit.json")
        self.offiaccountUrlQuery = request_data("OffiaccountUrlQuery.json")
        self.feetempServiceSubmit = request_data("FeetempServiceSubmit.json")
        self.orderFeeConfirmSubmit = request_data("OrderFeeConfirmSubmit.json")
        self.userLocationUpload = request_data("UserLocationUpload.json")


    @task(1)
    def TrackPointUpload(self):
        with self.client.post(path='/spcar/webapi/weapp/order/track/point/upload',json=self.pointUpload,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def FeeCalc(self):
        with self.client.post(path='/spcar/webapi/weapp/order/fee/calc',json=self.feeCalc,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                f.success()
            else:
                f.failure(f.text)

    @task(1)
    def ShareInit(self):
        with self.client.post(path='/spcar/webapi/weapp/share/init',json=self.feeCalc,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def UserInfoCheck(self):
        with self.client.post(path='/spcar/webapi/weapp/user/info/check',json=self.feeCalc,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def CurrentOrderInfo(self):
        with self.client.post(path='/spcar/webapi/weapp/order/info/current',json=self.currentOrderInfo,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)




    @task(1)
    def PlazaTeams(self):
        with self.client.post(path='/spcar/webapi/weapp/plaza/teams',json=self.plazaTeams,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def MsgList(self):
        with self.client.post(path='/spcar/webapi/weapp/user/msg/list',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def RoutingEvent(self):
        with self.client.post(path='/spcar/webapi/weapp/order/routing/event',json=self.routingEvent,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def UserInfoDetail(self):
        with self.client.post(path='/spcar/webapi/weapp/user/info/detail',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def MainHome(self):
        with self.client.post(path='/spcar/webapi/weapp/main/home',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def PlazaAccessPermissions(self):
        with self.client.post(path='/spcar/webapi/weapp/plaza/access/permissions',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def UserAlogin(self):
        with self.client.get(path='/spcar/webapi/weapp/user/alogin',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                f.success()
            else:
                f.failure(f.text)

    @task(1)
    def UserLocationUpload(self):
        with self.client.post(path='/spcar/webapi/weapp/user/location/upload',json=self.userLocationUpload,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)
    #接口作废
    # @task(1)
    # def PLazaOrdersMissing(self):
    #     with self.client.get(path='/spcar/webapi/weapp/plaza/orders/missing',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             f.success()
    #         else:
    #             f.failure(f.text)

    #接口已经作废了
    # @task(1)
    # def BadageDriverCurrentOrd(self):
    #     with self.client.get(path='/spcar/webapi/weapp/order/badge/driver/current/order',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)

    @task(1)
    def MainProfile(self):
        with self.client.post(path='/spcar/webapi/weapp/main/profile',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def UserMiniappSettings(self):
        with self.client.post(path='/spcar/webapi/weapp/user/miniapp/settings',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def MainHomeTips(self):
        with self.client.post(path='/spcar/webapi/weapp/main/home/tips',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def OrderInfoDetail(self):
        with self.client.post(path='/spcar/webapi/weapp/order/info/detail',json=self.orderInfoDetail,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def FeetempServiceList(self):
        with self.client.post(path='/spcar/webapi/weapp/feetemp/service/list',json=self.feeTempServiceList,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    # 接口作废
    # @task(1)
    # def OrderAcceptDetail(self):
    #     with self.client.get(path='/spcar/webapi/weapp/order/accept/detail',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)

    # @task(1)
    # def TeamDriverAuditNotify(self):
    #     with self.client.get(path='/spcar/webapi/weapp/team/driver/audit/notify',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)


    @task(1)
    def OrderFeeINcreaseMode(self):
        with self.client.post(path='/spcar/webapi/weapp/order/fee/increase/mode',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def UserBadgeListenSwitch(self):
        with self.client.post(path='/spcar/webapi/weapp/user/badge/listen/switch',json=self.userBadgeListenSwitch,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)
    #接口作废
    # @task(1)
    # def TeamDetail(self):
    #     with self.client.get(path='/spcar/webapi/weapp/team/detail',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)
    #接口作废
    # @task(1)
    # def TeamOrderList(self):
    #     with self.client.get(path='/spcar/webapi/weapp/team/order/list',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)

    @task(1)
    def UserHome(self):
        with self.client.post(path='/spcar/webapi/weapp/user/home',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def OrderInfoPayment(self):
        with self.client.post(path='/spcar/webapi/weapp/order/info/payment',json=self.orderInfoPayment,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)
    #未抓到包 确认接口还在用不
    @task(1)
    def MessageTemplateList(self):
        with self.client.post(path='/spcar/webapi/public/message/template/list',json=self.messageTemplateList,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def OrderFeeConfirmInit(self):
        with self.client.post(path='/spcar/webapi/weapp/order/fee/confirm/init',json=self.orderFeeConfirmInit,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                f.success()
            else:
                f.failure(f.text)

    #接口作废
    # @task(1)
    # def UserTeams(self):
    #     with self.client.post(path='/spcar/webapi/weapp/user/teams',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)

    @task(1)
    def OrderActionFinish(self):
        with self.client.post(path='/spcar/webapi/weapp/order/action/finish',json=self.orderActionFinish,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                f.success()
            else:
                f.failure(f.text)

    @task(1)
    def OrderInfoSubmitStart(self):
        with self.client.post(path='/spcar/webapi/weapp/order/info/submitstart',json=self.orderInfoSubmitStart,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                f.success()
            else:
                f.failure(f.text)


    @task(1)
    def OrderFeeConfirmSubmit(self):
        with self.client.post(path='/spcar/webapi/weapp/order/fee/confirm/submit',json=self.orderFeeConfirmSubmit,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                f.success()
            else:
                f.failure(f.text)


    @task(1)
    def MessageTemplateSubscribe(self):
        with self.client.post(path='/spcar/webapi/public/message/template/subscribe',json=self.messageTemplateSubscribe,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)
    #接口作废
    # @task(1)
    # def UserBadgeList(self):
    #     with self.client.post(path='/spcar/webapi/weapp/user/badge/list',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)


    @task(1)
    def OrderInfoList(self):
        with self.client.post(path='/spcar/webapi/weapp/order/info/list',json=self.orderInfoList,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def AdStatsInit(self):
        with self.client.post(path='/spcar/webapi/public/ad/stats/init',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def OrderActionWait(self):
        with self.client.post(path='/spcar/webapi/weapp/order/action/wait',json=self.orderActionWait,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                f.success()
            else:
                f.failure(f.text)

    @task(1)
    def FeetempServiceInfo(self):
        with self.client.post(path='/spcar/webapi/weapp/feetemp/service/detail',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def OffiaccountUrlQuery(self):
        with self.client.post(path='/spcar/webapi/public/offiaccount/url/query',json=self.offiaccountUrlQuery,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def UserDriveSettings(self):
        with self.client.post(path='/spcar/webapi/weapp/user/drive/settings',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    #接口作废
    # @task(1)
    # def TeamBizgrpDetail(self):
    #     with self.client.get(path='/spcar/webapi/weapp/team/bizgrp/detail',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)

    @task(1)
    def OrderTrackList(self):
        with self.client.post(path='/spcar/webapi/weapp/order/track/list',json=self.orderTrackList,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)
    #确认是否注销
    # @task(1)
    # def UserInfoWxdecrypt(self):
    #     with self.client.get(path='/spcar/webapi/weapp/user/info/wxdecrypt',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)


    @task(1)
    def OrderFeeCurrentIntro(self):
        with self.client.post(path='/spcar/webapi/weapp/order/fee/current/intro',json=self.orderFeeCurrentIntro,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                f.success()
            else:
                f.failure(f.text)

    @task(1)
    def UserMsgClose(self):
        with self.client.post(path='/spcar/webapi/weapp/user/msg/close',json=self.userMsgClose,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def Health(self):
        with self.client.get(path='/spcar/webapi/health',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def VerifyFaceidToken(self):
        with self.client.post(path='/spcar/webapi/public/verify/faceid/token',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def UserBalanceDaily(self):
        with self.client.post(path='/spcar/webapi/weapp/user/balance/daily',json=self.userBalanceDaily,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)
    #接口作废
    # @task(1)
    # def TeamJoinFree(self):
    #     with self.client.get(path='/spcar/webapi/weapp/team/join/free',json=self.teamJoinFree,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)
    #接口作废
    # @task(1)
    # def TeamOrderChart(self):
    #     with self.client.get(path='/spcar/webapi/weapp/team/order/chart',json=None,headers=self.h,catch_response=True) as f :
    #         if f.status_code==200:
    #             if json.loads(f.content.decode())['msg'] == 'success':
    #                 f.success()
    #             else:
    #                 f.failure(f.text)
    #         else:
    #             f.failure(f.text)

    @task(1)
    def FeetempServiceSubmit(self):
        with self.client.post(path='/spcar/webapi/weapp/feetemp/service/submit',json=self.feetempServiceSubmit,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def PlazaListen(self):
        with self.client.post(path='/spcar/webapi/weapp/plaza/listen',json=self.plazaListen,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    @task(1)
    def V2FleetList(self):
        with self.client.post(path='/spcar/webapi/weapp/v2/fleet/list',json=None,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)

    @task(1)
    def UserBadgeSettingSetup(self):
        with self.client.post(path='/spcar/webapi/weapp/user/badge/settings/setup',json=self.userBadgeSettingSetup,headers=self.h,catch_response=True) as f :
            if f.status_code==200:
                if json.loads(f.content.decode())['msg'] == 'success':
                    f.success()
                else:
                    f.failure(f.text)
            else:
                f.failure(f.text)


    # @task(1)
    # def WechatMsg(self):
    #     '''
    #     微信调用，暂时不做压测
    #     :return:
    #     '''
        # with self.client.post(path='/spcar/webapi/weapp/wechat/message/m_spcar',json=self.feeCalc,headers=self.h,catch_response=True) as f :
        #     resp = json.loads(f.content.decode())
        # logging.info(resp)
        # if f.status_code==200:
        #     if resp['msg'] == 'success':
        #         f.success()
        #     else:
        #         f.failure(resp)
        # else:
        #     f.failure(resp)

class WebsiteUser(FastHttpUser):
    tasks = [WebsiteTasks]


if __name__ == '__main__':
    os.system("locust -f %s --html=%s --csv=%s --config=%s"%(os.path.basename(__file__),reportName,reportName,masterConf))
